<template>
  <el-dialog
    :title="!dataForm.productId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="产品名称" prop="productName">
      <el-input v-model="dataForm.productName" placeholder="产品名称"></el-input>
    </el-form-item>
    <el-form-item label="产品编码" prop="productCode">
      <el-input v-model="dataForm.productCode" placeholder="产品编码"></el-input>
    </el-form-item>
    <!-- <el-form-item label="${column.comments}" prop="productTypeId">
      <el-input v-model="dataForm.productTypeId" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="产品描述" prop="productDesc">
      <el-input v-model="dataForm.productDesc" placeholder="产品描述"></el-input>
    </el-form-item>
    <!-- <el-form-item label="${column.comments}" prop="productLogo">
      <el-input v-model="dataForm.productLogo" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderCount">
      <el-input v-model="dataForm.orderCount" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="产品最低价格" prop="productPrice">
      <el-input v-model="dataForm.productPrice" placeholder="产品最低价格"></el-input>
    </el-form-item>
    <!-- <el-form-item label="${column.comments}" prop="productImg">
      <el-input v-model="dataForm.productImg" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="产品副标题" prop="productSubname">
      <el-input v-model="dataForm.productSubname" placeholder="产品副标题"></el-input>
    </el-form-item>
    <!-- <el-form-item label="${column.comments}" prop="insureLogo">
      <el-input v-model="dataForm.insureLogo" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="保险公司编码" prop="insureCode">
      <el-input v-model="dataForm.insureCode" placeholder="保险公司编码"></el-input>
    </el-form-item>
    <el-form-item label="保险公司名称" prop="insureName">
      <el-input v-model="dataForm.insureName" placeholder="保险公司名称"></el-input>
    </el-form-item>
    <el-form-item label="保险期限描述" prop="insureDate">
      <el-input v-model="dataForm.insureDate" placeholder="保险期限描述"></el-input>
    </el-form-item>
    <!-- <el-form-item label="${column.comments}" prop="insureDateNum">
      <el-input v-model="dataForm.insureDateNum" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="insureDateUnit">
      <el-input v-model="dataForm.insureDateUnit" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="出单机构" prop="issueOrgan">
      <el-input v-model="dataForm.issueOrgan" placeholder="出单机构"></el-input>
    </el-form-item>
    <!-- <el-form-item label="${column.comments}" prop="description">
      <el-input v-model="dataForm.description" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="instructionsDesc">
      <el-input v-model="dataForm.instructionsDesc" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="claimsDesc">
      <el-input v-model="dataForm.claimsDesc" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="insureAgreement">
      <el-input v-model="dataForm.insureAgreement" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="insureRepay">
      <el-input v-model="dataForm.insureRepay" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createPersonId">
      <el-input v-model="dataForm.createPersonId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="updatePersonId">
      <el-input v-model="dataForm.updatePersonId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="deleteTime">
      <el-input v-model="dataForm.deleteTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="deletePersonId">
      <el-input v-model="dataForm.deletePersonId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderNumber">
      <el-input v-model="dataForm.orderNumber" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="状态" prop="state">
      <el-input v-model="dataForm.state" placeholder="状态(0启用1不启动)"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          productId: 0,
          productName: '',
          productCode: '',
          productTypeId: '',
          productDesc: '',
          productLogo: '',
          orderCount: '',
          productPrice: '',
          productImg: '',
          productSubname: '',
          insureLogo: '',
          insureCode: '',
          insureName: '',
          insureDate: '',
          insureDateNum: '',
          insureDateUnit: '',
          issueOrgan: '',
          description: '',
          instructionsDesc: '',
          claimsDesc: '',
          insureAgreement: '',
          insureRepay: '',
          createTime: '',
          createPersonId: '',
          updateTime: '',
          updatePersonId: '',
          deleteTime: '',
          deletePersonId: '',
          orderNumber: '',
          state: ''
        },
        dataRule: {
          productName: [
            { required: true, message: '产品名称不能为空', trigger: 'blur' }
          ],
          productCode: [
            { required: true, message: '产品编码不能为空', trigger: 'blur' }
          ],
          productTypeId: [
            { required: true, message: '保险类型不能为空', trigger: 'blur' }
          ],
          productDesc: [
            { required: true, message: '产品描述不能为空', trigger: 'blur' }
          ],
          productLogo: [
            { required: true, message: '产品logo不能为空', trigger: 'blur' }
          ],
          orderCount: [
            { required: true, message: '销售量不能为空', trigger: 'blur' }
          ],
          productPrice: [
            { required: true, message: '产品最低价格不能为空', trigger: 'blur' }
          ],
          productImg: [
            { required: true, message: '产品大图不能为空', trigger: 'blur' }
          ],
          productSubname: [
            { required: true, message: '产品副标题不能为空', trigger: 'blur' }
          ],
          insureLogo: [
            { required: true, message: '保险公司logo不能为空', trigger: 'blur' }
          ],
          insureCode: [
            { required: true, message: '保险公司编码或Id不能为空', trigger: 'blur' }
          ],
          insureName: [
            { required: true, message: '保险公司名称不能为空', trigger: 'blur' }
          ],
          insureDate: [
            { required: true, message: '保险期限描述不能为空', trigger: 'blur' }
          ],
          insureDateNum: [
            { required: true, message: '保险期限数量不能为空', trigger: 'blur' }
          ],
          insureDateUnit: [
            { required: true, message: '保险期限单位不能为空', trigger: 'blur' }
          ],
          issueOrgan: [
            { required: true, message: '出单机构不能为空', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '产品介绍不能为空', trigger: 'blur' }
          ],
          instructionsDesc: [
            { required: true, message: '投保须知img不能为空', trigger: 'blur' }
          ],
          claimsDesc: [
            { required: true, message: '理赔流程img不能为空', trigger: 'blur' }
          ],
          insureAgreement: [
            { required: true, message: '保险协议不能为空', trigger: 'blur' }
          ],
          insureRepay: [
            { required: true, message: '偿还能力披露不能为空', trigger: 'blur' }
          ],
          orderNumber: [
            { required: true, message: '排序不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.productId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.productId) {
            this.$http({
              url: this.$http.adornUrl(`/product/product/info/${this.dataForm.productId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              console.info(data)
              if (data && data.code === 0) {
                this.dataForm.productName = data.product.productName
                this.dataForm.productCode = data.product.productCode
                this.dataForm.productTypeId = data.product.productTypeId
                this.dataForm.productDesc = data.product.productDesc
                this.dataForm.productLogo = data.product.productLogo
                this.dataForm.orderCount = data.product.orderCount
                this.dataForm.productPrice = data.product.productPrice
                this.dataForm.productImg = data.product.productImg
                this.dataForm.productSubname = data.product.productSubname
                this.dataForm.insureLogo = data.product.insureLogo
                this.dataForm.insureCode = data.product.insureCode
                this.dataForm.insureName = data.product.insureName
                this.dataForm.insureDate = data.product.insureDate
                this.dataForm.insureDateNum = data.product.insureDateNum
                this.dataForm.insureDateUnit = data.product.insureDateUnit
                this.dataForm.issueOrgan = data.product.issueOrgan
                this.dataForm.description = data.product.description
                this.dataForm.instructionsDesc = data.product.instructionsDesc
                this.dataForm.claimsDesc = data.product.claimsDesc
                this.dataForm.insureAgreement = data.product.insureAgreement
                this.dataForm.insureRepay = data.product.insureRepay
                this.dataForm.createTime = data.product.createTime
                this.dataForm.createPersonId = data.product.createPersonId
                this.dataForm.updateTime = data.product.updateTime
                this.dataForm.updatePersonId = data.product.updatePersonId
                this.dataForm.deleteTime = data.product.deleteTime
                this.dataForm.deletePersonId = data.product.deletePersonId
                this.dataForm.orderNumber = data.product.orderNumber
                this.dataForm.state = data.product.state
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/product/product/${!this.dataForm.productId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'productId': this.dataForm.productId || undefined,
                'productName': this.dataForm.productName,
                'productCode': this.dataForm.productCode,
                'productTypeId': this.dataForm.productTypeId,
                'productDesc': this.dataForm.productDesc,
                'productLogo': this.dataForm.productLogo,
                'orderCount': this.dataForm.orderCount,
                'productPrice': this.dataForm.productPrice,
                'productImg': this.dataForm.productImg,
                'productSubname': this.dataForm.productSubname,
                'insureLogo': this.dataForm.insureLogo,
                'insureCode': this.dataForm.insureCode,
                'insureName': this.dataForm.insureName,
                'insureDate': this.dataForm.insureDate,
                'insureDateNum': this.dataForm.insureDateNum,
                'insureDateUnit': this.dataForm.insureDateUnit,
                'issueOrgan': this.dataForm.issueOrgan,
                'description': this.dataForm.description,
                'instructionsDesc': this.dataForm.instructionsDesc,
                'claimsDesc': this.dataForm.claimsDesc,
                'insureAgreement': this.dataForm.insureAgreement,
                'insureRepay': this.dataForm.insureRepay,
                'createTime': this.dataForm.createTime,
                'createPersonId': this.dataForm.createPersonId,
                'updateTime': this.dataForm.updateTime,
                'updatePersonId': this.dataForm.updatePersonId,
                'deleteTime': this.dataForm.deleteTime,
                'deletePersonId': this.dataForm.deletePersonId,
                'orderNumber': this.dataForm.orderNumber,
                'state': this.dataForm.state
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
